package com.sgb.member.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle;

import com.sgb.member.R;
import com.sgb.member.entity.MemberBean;
import com.sgb.member.ui.fragment.CompanyWebFragment;
import com.swgk.core.base.AppActivity;

public class MemberPriceActivity extends AppActivity {

    /**
     * @param memberBean MemberBean memberBean = new MemberBean();
     *                   memberBean.setMemberUpdateLeverType(""); //1供方会员 2需方会员
     *                   memberBean.setCompanyNo("");
     */
    public static void start(Context context, MemberBean memberBean) {
        Intent intent = new Intent(context, MemberPriceActivity.class);
        intent.putExtra("EXTRA_BEAN", memberBean);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        super.initView();
        MemberBean memberBean = (MemberBean) getIntent().getSerializableExtra("EXTRA_BEAN");
        setContentView(R.layout.activity_member_price);
        TextView textView = findViewById(R.id.title_view);
        ImageView imageView = findViewById(R.id.iv_back);
        boolean isDemandMember = TextUtils.equals("2", memberBean.getMemberUpdateLeverType()); //1供方会员 2需方会员
        if (isDemandMember) {
            textView.setText("会员调价");
        } else {
            textView.setText("会员查价");
        }
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        loadFragment(memberBean);
    }

    private void loadFragment(MemberBean memberBean) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = manager.beginTransaction();
        CompanyWebFragment companyWebFragment = CompanyWebFragment.newInstance(0, memberBean);
        fragmentTransaction.add(R.id.container, companyWebFragment);
        fragmentTransaction.setMaxLifecycle(companyWebFragment, Lifecycle.State.RESUMED);
        fragmentTransaction.commit();
    }
}
